<?php
header('Content-Type: application/json');

// 获取前端发送的user数据
$user = isset($_GET['user']) ? $_GET['user'] : '';

// 获取分页参数
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10;

// 连接数据库
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "fish";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

// 根据用户查询模型数据
$sql = "SELECT * FROM vuemodel WHERE user = ? LIMIT ? OFFSET ?";
$offset = ($page - 1) * $limit;
$stmt = $conn->prepare($sql);
$stmt->bind_param("sii", $user, $limit, $offset);
$stmt->execute();
$result = $stmt->get_result();

// 将结果转换为关联数组
$models = array();
while($row = $result->fetch_assoc()) {
    $models[] = $row;
}

// 释放结果集
$result->free();

// 关闭连接
$conn->close();

// 将结果以JSON格式返回
echo json_encode($models);
?>
